package com.example.hanqinshan.gifttalk.rank;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.hanqinshan.gifttalk.entity.RankEntity;
import com.example.hanqinshan.gifttalk.rank.item.RankItemFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/29.
 */
public class RankPagerAdapter extends FragmentPagerAdapter {
    private List<RankEntity> ranks;

    public RankPagerAdapter (FragmentManager fm) {
        super(fm);
        ranks = new ArrayList<>();
    }

    public void addAll(List<RankEntity> ranks){
        this.ranks.clear();
        this.ranks.addAll(ranks);
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem (int position) {
        return RankItemFragment.newInstance(ranks.get(position).getId());
    }

    @Override
    public int getCount () {
        return ranks.size();
    }

    @Override
    public CharSequence getPageTitle (int position) {
        return ranks.get(position).getName();
    }
}
